package com.bss.service.impl;

import com.bss.dao.CustomerMapper;
import com.bss.pojo.Customer;
import com.bss.pojo.CustomerExample;
import com.bss.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 袁飞
 * @company 中原工学院
 * @create 2020-03-14-19:35
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    CustomerMapper customerMapper;
    public int addCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    public int updateCustomer(Customer customer) {
        return customerMapper.updateByPrimaryKeySelective(customer);
    }

    public Customer findCustomerById(Integer id) {
        return customerMapper.selectByPrimaryKey(id);
    }

    public int deleteCustomerById(Integer id) {
        return customerMapper.deleteByPrimaryKey(id);
    }

    public List<Customer> findAll() {
        CustomerExample customerExample = new CustomerExample();
        CustomerExample.Criteria criteria = customerExample.createCriteria();
        return customerMapper.selectByExample(customerExample);
    }

    public Customer findByName(String customerName) {
        return customerMapper.selectByName(customerName);
    }

    public List<Customer> findCustomer(String customerName, String customerAddr) {
        CustomerExample customerExample = new CustomerExample();
        CustomerExample.Criteria criteria = customerExample.createCriteria();
        criteria.andCustomerAddrLike("%"+customerAddr+"%");
        criteria.andCustomerNameLike("%"+customerName+"%");
        return customerMapper.selectByExample(customerExample);
    }

}
